package Demo1;

public class MyLinkList {
    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
            this.next = null;
            this.prev = null;
            //prev 和 next 为空
        }
    }
    public ListNode head;//标记双向链表的头部
    public ListNode tail;//标记双向链表的尾部

    public void addFirst(int data){
        ListNode newNode = new  ListNode(data);
        if(head == null){
            head = newNode;
            head.prev = null;
            head.next = null;
        }else{
            newNode.next = this.head;
            this.head.prev = newNode;
            this.head = newNode;
        }
    }
    public void display(){
        ListNode cur = head;
        if(cur == null){
            return;
        }
        while(cur != null){
            System.out.print (cur.val+" ");
            cur = cur.next;

//            if(cur.next == cur){
//                break;
//            }
        }
        System.out.println();
    }

    }
